<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class Peserta_fix extends CI_Controller {

    public function __construct() {
        parent::__construct();
        $this->load->helper('flexigrid');
        $this->load->library('flexigrid');
        $this->load->library('session');
        $this->load->model('user_man_model');
        $this->load->helper('generate_pdf');
        $this->load->model('peserta_fix_model');
        $this->load->model('peserta_model');
        $this->load->model('batch_model');
		$this->cek_login();
    }

	
	function cek_login(){
		$id_hak = $this->session->userdata('id_hak');
		if($id_hak < 1 || $id_hak > 2 || $id_hak == ''){
			redirect ('login');
		}
		
	}

    //load data grid
    function index() {
        $id_batch = $this->input->post('batch');
        if ($id_batch == null) {
            if ($this->session->userdata('id_batch') == null) {
                $id_batch = 0;
            } else {
                $id_batch = $this->session->userdata('id_batch');
            }
        }
        $this->daftar($id_batch);
    }

    function daftar($id_batch) {
        $this->session->set_userdata('id_batch', $id_batch);

        $colModel['no'] = array('No', 30, TRUE, 'center', 0);
		$colModel['Id_Peserta'] = array('No Peserta', 70, TRUE, 'center', 1);
        $colModel['Nama_Peserta'] = array('Nama Peserta', 120, TRUE, 'center', 1);
        $colModel['Jenis_Kelamin'] = array('Jenis Kelamin', 75, TRUE, 'center', 0);
        $colModel['Tempat_Lahir'] = array('Tempat Lahir', 75, TRUE, 'center', 1);
        $colModel['No_HP'] = array('No HP', 75, TRUE, 'center', 1);
        $colModel['Pekerjaan'] = array('Pekerjaan', 100, TRUE, 'center', 1);
        $colModel['Jenis_Usaha'] = array('Jenis Usaha', 120, TRUE, 'center', 1);
        $colModel['Omset'] = array('Omset', 75, TRUE, 'left', 0);
        $colModel['Status'] = array('Status Lulus', 70, TRUE, 'center', 0);
        $colModel['Edit'] = array('Edit', 30, TRUE, 'center', 0);


        //get nama batch
        $nama_batch = '-';
        $data_batch = $this->batch_model->selectone($id_batch);
        foreach ($data_batch->result() as $row) {
            $nama_batch = $row->NAMA_BATCH;
        }

        $gridParams = array(
            'width' => 'auto',
            'height' => 300,
            'rp' => 10,
            'rpOptions' => '[5,10,15,20,25,40]',
            'pagestat' => 'Menampilkan: {from} hingga {to} dari {total} data.',
            'blockOpacity' => 0.5,
            'title' => 'Daftar Peserta Fix ' . $nama_batch,
            'showTableToggleBtn' => true
        );

        $buttons[] = array('Hapus', 'delete', 'spt_js');
        $buttons[] = array('separator');
        $buttons[] = array('Plot Kamar Peserta', 'print', 'spt_js');
        $buttons[] = array('separator');
        $buttons[] = array('Cetak Daftar Pembagian Kamar Peserta', 'print', 'spt_js');
        $buttons[] = array('separator');
        $buttons[] = array('Cetak Tempel Kamar', 'print', 'spt_js');
        $buttons[] = array('separator');
        $buttons[] = array('Cetak Kartu Peserta', 'print', 'spt_js');

        // mengambil data dari file controler ajax pada method grid_berkas
        $grid_js = build_grid_js('flex1', site_url("peserta/peserta_fix/grid_peserta_fix/" . $id_batch), $colModel, 'Nama_Peserta', 'asc', $gridParams, $buttons);


        //additional JS
        $data['added_js'] =
                "<script type='text/javascript'>
		function spt_js(com,grid)
		{
			if (com=='Tambah')
			{
				location.href='" . base_url() . "index.php/peserta/peserta/form_peserta'; 
			}
			
			if (com=='Hapus')
				{
				   if($('.trSelected',grid).length>0){
					   if(confirm('Anda yakin menghapus ' + $('.trSelected',grid).length + ' data peserta?')){
							var items = $('.trSelected',grid);
							var itemlist ='';
							for(i=0;i<items.length;i++){
								itemlist+= items[i].id.substr(3)+',';
							}
							$.ajax({
							   type: 'POST',
							   url: '" . base_url() . "index.php/peserta/peserta/delete" . "',
							   data: 'items='+itemlist,
							   success: function(data){
								$('#flex1').flexReload();
							   }
							});
						}
					} else {
						return false;
					} 
				}

			if (com=='Plot Kamar Peserta')
			{
				location.href='" . base_url() . "index.php/peserta/peserta_fix/plot_kamar/" . $id_batch . "'; 
			}
			
			if (com=='Cetak Daftar Pembagian Kamar Peserta')
			{
				location.href='" . base_url() . "index.php/peserta/peserta_fix/cetak_kamar/true/" . $id_batch . "'; 
			}

			if (com=='Cetak Tempel Kamar')
			{
				location.href='" . base_url() . "index.php/peserta/peserta_fix/cetak_tempel_kamar/true/" . $id_batch . "'; 
			}
			
			if (com=='Cetak Kartu Peserta')
			{
				location.href='" . base_url() . "index.php/peserta/peserta_fix/cetak_nametag/true/" . $id_batch . "'; 
			}

		}
		</script>
		";


        $data_grid['js_grid'] = $grid_js;
        //get data batch
        $data['id_batch'] = $id_batch;
        // if ($this->session->userdata('id_hak') == 1) {
            // $data['batch'] = $this->batch_model->get_all_batch();
        // } else {
            $data['batch'] = $this->batch_model->get_batch($this->session->userdata('id_lisensi'));
        //}

        //remdering view
        $data['title'] = 'Daftar Peserta Fix';
        $this->template->write_view('header', 'template/header', $data);
        $this->template->write_view('content', 'peserta/grid_peserta_fix', $data_grid);
        $this->template->write_view('footer', 'template/footer', $data);
        $this->template->render();
    }

    function grid_peserta_fix($id_batch) {
        $valid_fields = array('Id_Peserta','Nama_Peserta', 'Jenis_Kelamin', 'Tempat_Lahir', 'No_HP', 'Pekerjaan', 'Jenis_Usaha', 'Omset', 'Status');
        $this->flexigrid->validate_post('Nama_Peserta', 'asc', $valid_fields);
        $records = $this->peserta_fix_model->get_data_peserta($id_batch);
        $this->output->set_header($this->config->item('json_header'));

        $no = 0;
        foreach ($records['records']->result() as $row) {
            //set status peserta
            $status = '';
            $link = '';
            if ($row->STATUS_PESERTA == '1') {
                $status = '<img border=\'0\' src=\'' . base_url() . 'images/grid/not_yet.png\'>';
				$link = '<a href=\'' . base_url() . 'index.php/peserta/peserta_fix/status/' . $row->ID_PESERTA . '\'>';
            } else if ($row->STATUS_PESERTA == '2') {
                $status = '<img border=\'0\' src=\'' . base_url() . 'images/grid/fix.png\'>';
            }


            $record_items[] = array(
                $row->ID_PESERTA,
                $no = $no + 1,
				$row->ID_PESERTA,
                $row->NAMA_PESERTA,
                $row->JENIS_KELAMIN,
                $row->TEMPAT_LAHIR,
                $row->NO_HP,
                $row->PEKERJAAN,
                $row->JENIS_USAHA,
                'Rp. ' . $row->OMSET . ',-',
                ''.$link.'' . $status . '</a> ',
                '<a href=\'' . base_url() . 'index.php/peserta/peserta/edit/' . $row->ID_PESERTA . '\'><img border=\'0\' src=\'' . base_url() . 'images/grid/edit.png\'></a> '
            );
        }

        if (isset($record_items))
            $this->output->set_output($this->flexigrid->json_build($records['record_count'], $record_items));
        else
            $this->output->set_output('{"page":"1","total":"0","rows":[]}');
    }

    //status peserta
    public function status($id) {
        $records = $this->peserta_model->selectone($id);
        foreach ($records->result() as $row) {
            //set status peserta
            $status_baru = '';
            $nama = '';
            $email = '';
            if ($row->STATUS_PESERTA == '1') {
                //$data['status_baru'] = 2;
                $data2 = array('STATUS_PESERTA' => 2);
                $record_peserta = $this->peserta_model->selectone($id);
                //get data peserta for alumni
                foreach ($record_peserta->result() as $peserta) {

                    $data['nama_alumni'] = $peserta->NAMA_PESERTA;
                    $nama = $peserta->NAMA_PESERTA;
                    $data['nama_panggilan'] = $peserta->NAMA_PANGGILAN;
                    $data['jenis_kelamin'] = $peserta->JENIS_KELAMIN;
                    $data['tempat_lahir'] = $peserta->TEMPAT_LAHIR;
                    $data['tanggal_lahir'] = '' . $peserta->TAHUN . '-' . $peserta->BULAN . '-' . $peserta->TANGGAL . '';
                    $data['nama_usaha'] = $peserta->NAMA_USAHA;
                    $data['jenis_usaha'] = $peserta->JENIS_USAHA;
                    $data['omset'] = $peserta->OMSET;
                    $data['pekerjaan'] = $peserta->PEKERJAAN;
                    $data['no_hp'] = $peserta->NO_HP;
                    $data['email'] = $peserta->EMAIL;
                    $email = $peserta->EMAIL;
                    $data['twitter'] = $peserta->TWITTER;
                    $data['alamat'] = $peserta->ALAMAT;
                    $data['kode_pos'] = $peserta->KODE_POS;
                    $data['id_kota'] = $peserta->ID_KOTA;
                    $data['id_batch'] = $peserta->ID_BATCH;
                    $data['status'] = 1;
                }


                //finish
                //update status to alumni and insert alumni's data
                $this->peserta_fix_model->update_status($id, $data2);
                $this->peserta_fix_model->insert_alumni($data);

                //create account for alumni
                $query = $this->peserta_fix_model->get_lisensi($this->session->userdata('id_batch'));
                foreach ($query->result() as $row) {
                    $id_lisensi = $row->ID_LISENSI;
                }

                $record_alumni = $this->peserta_fix_model->get_alumni($email);
				//create alumni user for login
				$password	= rand(100000,999999);
                foreach ($record_alumni->result() as $rows) {
					$email = $rows->EMAIL;
                    $data3['username'] = $rows->EMAIL;
                    $data3['password'] = md5($password);
                    $data3['id_privilage'] = 3;
                    $data3['id_lisensi'] = $id_lisensi;
                    $data3['id_alumni'] = $rows->ID_ALUMNI;
                    $data3['status'] = 1;
                }
				
				//START KIRIM EMAIL NOTIFIKASI KE PESERTA
				$config['protocol']		= 'smtp';
				$config['smtp_host']	= 'ssl://smtp.googlemail.com';
				$config['smtp_port']	= 465;
				$config['smtp_user']	= 'fiian91@gmail.com';
				$config['smtp_pass']	= '18mei1991';
				$this->load->library('email', $config);
				$this->email->set_newline("\r\n");
				//$message	= "Permintaan Anda sudah kami terima.\nSilahkan Lakukan pembayaran sesuai jumlah modul yang dipesan.\na. Invoice ini hanya berlaku seminggu, harap transfer dalam seminggu ini.\nb. Bila mungkin, harap mengisi kolom keterangan transfer dengan UserID referral.\n\n\nTerimakasih.";
				$message = "Selamat Anda telah sukses mengikuti pelatihan E-Camp Indonesia dan Anda telah tergabung dalam ikatan alumni Ecamp Indonesia.\nAnda dapat mengakses website alumni (http://localhost/ta/index.php/login) dengan\nUsername : ".$email."\nPassword : ".$password."\n\nSegera ubah password Anda dan perbarui data identitas Anda untuk menambah relasi dengan alumni lain.\n\nJika terdapat masalah Anda dapat menghubungi E-Camp Indonesia melalui:\nEmail : info@ecampindonesia.com\nTelp : 025451212\n\n-Terimakasih-";
				
				$this->email->from('fiian91@gmail.com', 'EcampIndonesia');
				$this->email->to($email);
				$this->email->subject('Notifikasi Alumni E-Camp');
				$this->email->message($message);
		
				$this->email->send();				
				//$this->email->print_debugger();
				//END KIRIM EMAIL NOTIFIKASI KE PESERTA
				
				
				//input ke DB
                $this->user_man_model->insert_user($data3);
                //finish

                redirect('peserta/peserta_fix/daftar/' . $this->session->userdata('id_batch'));
            } else if ($row->STATUS_PESERTA == '2') {
                $data = array('STATUS_PESERTA' => 1);
                $this->peserta_fix_model->update_status($id, $data);
                redirect('peserta/peserta_fix/daftar/' . $this->session->userdata('id_batch'));
            }
        }
    }

    public function detail($id) {
        $record_peserta = $this->peserta_model->selectone($id);
        foreach ($record_peserta->result() as $peserta) {
            $data['id_peserta'] = $peserta->ID_PESERTA;
            $data['nama_peserta'] = $peserta->NAMA_PESERTA;
            $data['nama_panggilan'] = $peserta->NAMA_PANGGILAN;
            $data['jenis_kelamin'] = $peserta->JENIS_KELAMIN;
            $data['tempat_lahir'] = $peserta->TEMPAT_LAHIR;
            $data['tanggal'] = $peserta->TANGGAL;
            $data['bulan'] = $peserta->BULAN;
            $data['tahun'] = $peserta->TAHUN;
            $data['nama_usaha'] = $peserta->NAMA_USAHA;
            $data['jenis_usaha'] = $peserta->JENIS_USAHA;
            $data['omset'] = $peserta->OMSET;
            $data['pekerjaan'] = $peserta->PEKERJAAN;
            $data['no_hp'] = $peserta->NO_HP;
            $data['no_darurat'] = $peserta->NO_DARURAT;
            $data['hub_darurat'] = $peserta->HUB_DARURAT;
            $data['email'] = $peserta->EMAIL;
            $data['twitter'] = $peserta->TWITTER;
            $data['ukuran_baju'] = $peserta->UKURAN_BAJU;
            $data['alamat'] = $peserta->ALAMAT;
            $data['kode_pos'] = $peserta->KODE_POS;
            $data['kota'] = $peserta->KOTA;
            $data['referensi'] = $peserta->REFERENSI;
            $data['no_transfer'] = $peserta->NO_TRANSFER;
            $data['tanggal_pembayaran'] = $peserta->TANGGAL_PEMBAYARAN;
            $data['promo'] = $peserta->PROMO;
            $data['informasi'] = $peserta->INFORMASI;
            $data['id_batch'] = $peserta->ID_BATCH;
        }

        //get data batch
        $id = 1;
        $data['batch'] = $this->batch_model->get_batch($id);


        $data['status'] = 'preview';
        $data['title'] = 'Daftar Peserta';
        $this->template->write_view('header', 'template/header', $data);
        $this->template->write_view('content', 'peserta/form_peserta_fix', $data);
        $this->template->write_view('footer', 'template/footer', $data);
        $this->template->render();
    }

    public function plot_kamar($id_batch) {

        //start cek data batch
        $sql = $this->db->query("SELECT COUNT(ID_BATCH) AS CEK_BATCH FROM KAMAR WHERE ID_BATCH = " . $id_batch . "");
        $cek_batch = '';
        foreach ($sql->result() as $rows) {
            $cek_batch = $rows->CEK_BATCH;
        }
        if ($cek_batch > 0) {
            redirect('peserta/peserta_fix/edit_plot_kamar/' . $id_batch . '');
        }
        //end cek
        else {
            $this->session->set_userdata('id_batch', $id_batch);

            $data['title'] = 'Plot Kamar Peserta';
            $data['plot_kamar_peserta_cow'] = $this->peserta_fix_model->plot_kamar_cow($id_batch);
            $data['plot_kamar_peserta_cew'] = $this->peserta_fix_model->plot_kamar_cew($id_batch);

            $this->template->write_view('header', 'template/header', $data);
            $this->template->write_view('content', 'peserta/plot_peserta', $data);
            $this->template->write_view('footer', 'template/footer', $data);
            $this->template->render();
        }
    }

    public function regenerate_plot_kamar($id_batch) {
        $this->session->set_userdata('id_batch', $id_batch);
        $this->peserta_fix_model->delete_kamar($this->session->userdata('id_batch'));
        
        $data['title'] = 'Plot Kamar Peserta';
        $data['plot_kamar_peserta_cow'] = $this->peserta_fix_model->plot_kamar_cow($id_batch);
        $data['plot_kamar_peserta_cew'] = $this->peserta_fix_model->plot_kamar_cew($id_batch);

        $this->template->write_view('header', 'template/header', $data);
        $this->template->write_view('content', 'peserta/plot_peserta', $data);
        $this->template->write_view('footer', 'template/footer', $data);
        $this->template->render();
    }

    public function save_plot_kamar() {
        $counter = 1;
        $counter_nokamar = 1;
        //$peserta = 1;
        while ($counter <= $this->input->post('status')) {
            $counter_plus = $counter + 1;
            $data = array(
                'ID_BATCH' => $this->session->userdata('id_batch'),
                'NO_KAMAR' => $this->input->post('no_kamar' . $counter_nokamar),
                'PESERTA_1' => $this->input->post('peserta' . $counter),
                'PESERTA_2' => $this->input->post('peserta' . $counter_plus)
            );

            $this->peserta_fix_model->save_plot_kamar($data);

            $counter = $counter + 2;
            $counter_nokamar++;
        }
        redirect('peserta/peserta_fix/daftar/' . $this->session->userdata('id_batch'));
    }

    public function edit_plot_kamar($id_batch) {

        $this->session->set_userdata('id_batch', $id_batch);

        $data['title'] = 'Plot Kamar Peserta';
        $data['plot_kamar_peserta'] = $this->peserta_fix_model->get_data_kamar($id_batch);

        $this->template->write_view('header', 'template/header', $data);
        $this->template->write_view('content', 'peserta/plot_peserta_edit', $data);
        $this->template->write_view('footer', 'template/footer', $data);
        $this->template->render();
    }

    public function update_plot_kamar() {
        $counter = 1;
        $counter_nokamar = 1;
        //$peserta = 1;

        $this->peserta_fix_model->delete_kamar($this->session->userdata('id_batch'));

        while ($counter <= $this->input->post('status')) {
            $counter_plus = $counter + 1;
            $data = array(
                'ID_BATCH' => $this->session->userdata('id_batch'),
                'NO_KAMAR' => $this->input->post('no_kamar' . $counter_nokamar),
                'PESERTA_1' => $this->input->post('peserta' . $counter),
                'PESERTA_2' => $this->input->post('peserta' . $counter_plus)
            );

            $this->peserta_fix_model->save_plot_kamar($data);

            $counter = $counter + 2;
            $counter_nokamar++;
        }
        redirect('peserta/peserta_fix/daftar/' . $this->session->userdata('id_batch'));
    }

    public function preview($id_batch) {
        $data['peserta'] = $this->peserta_fix_model->get_data_peserta_fix($id_batch);
        //get nama batch
        $nama_batch = '-';
        $data_batch = $this->batch_model->selectone($id_batch);
        foreach ($data_batch->result() as $row) {
            $nama_batch = $row->NAMA_BATCH;
        }

        //start count jumlah peserta
        $sql = $this->db->query("SELECT COUNT(ID_PESERTA) AS CEK_JUMLAH FROM PESERTA WHERE ID_BATCH = " . $id_batch . " AND STATUS_PESERTA>0 AND STATUS>0");
        $jumlah_peserta = '';
        foreach ($sql->result() as $rows) {
            $jumlah_peserta = $rows->CEK_JUMLAH;
        }

        //$data['peserta'] = $this->peserta_fix_model->get_data_peserta_fix($id_batch);
        $data['nama_batch'] = $nama_batch;
        $data['jumlah_peserta'] = $jumlah_peserta;
        $data['header_foto'] = "" . base_url() . "/images/print/header_kamar.jpg";
        $data['footer_foto'] = "" . base_url() . "/images/print/footer_kamar.jpg";
        $this->load->view("peserta/cetak_name_tag", $data);
    }

    //generate PDF cetak plot kamar
    function cetak_kamar($download_pdf = '', $id_batch) {
        $ret = '';

        //get nama batch
        $nama_batch = '-';
        $data_batch = $this->batch_model->selectone($id_batch);
        foreach ($data_batch->result() as $row) {
            $nama_batch = $row->NAMA_BATCH;
        }

        $pdf_filename = 'Pembagian Kamar ' . $nama_batch . '' . '.pdf';
        $link_download = ($download_pdf == TRUE) ? '' : anchor(base_url() . 'peserta_fix/printPDF/true/' . $id_batch, 'Download Pdf');

        $data['peserta'] = $this->peserta_fix_model->get_data_kamar($id_batch);
        $data['nama_batch'] = $nama_batch;
        $this->load->view("peserta/cetak_kamar_peserta", $data);

        $data_kamar = array(
            'data_info' => $data,
            'link_download' => $link_download
        );

        $user_info = $this->load->view('peserta/cetak_kamar_peserta', $data_kamar, true);

        if ($download_pdf == TRUE)
            generate_pdf($user_info, $pdf_filename, "potrait");
        else {
            echo $user_info;
        }
    }

    //generate PDF cetak tempel kamar
    function cetak_tempel_kamar($download_pdf = '', $id_batch) {
        $ret = '';

        //get nama batch
        $nama_batch = '-';
        $data_batch = $this->batch_model->selectone($id_batch);
        foreach ($data_batch->result() as $row) {
            $nama_batch = $row->NAMA_BATCH;
        }

        $pdf_filename = 'Pembagian Kamar ' . $nama_batch . '' . '.pdf';
        $link_download = ($download_pdf == TRUE) ? '' : anchor(base_url() . 'peserta_fix/printPDF/true/' . $id_batch, 'Download Pdf');

        //start count jumlah peserta
        $sql = $this->db->query("SELECT COUNT(ID_BATCH) AS CEK_JUMLAH FROM KAMAR WHERE ID_BATCH = " . $id_batch . "");
        $jumlah_peserta = '';
        foreach ($sql->result() as $rows) {
            $jumlah_peserta = $rows->CEK_JUMLAH;
        }

        $data['peserta'] = $this->peserta_fix_model->get_data_kamar($id_batch);
        $data['nama_batch'] = $nama_batch;
        $data['jumlah_peserta'] = $jumlah_peserta;
        $data['header_foto'] = "images/print/header_kamar.jpg";
        $data['footer_foto'] = "images/print/footer_kamar.jpg";
        $this->load->view("peserta/cetak_tempel_kamar", $data);

        $data_kamar = array(
            'data_info' => $data,
            'link_download' => $link_download
        );

        $user_info = $this->load->view('peserta/cetak_tempel_kamar', $data_kamar, true);

        if ($download_pdf == TRUE)
            generate_pdf($user_info, $pdf_filename, "landscape");
        else {
            echo $user_info;
        }
    }

    public function cetak_nametag($download_pdf = '', $id_batch) {
        $ret = '';

        //get nama batch
        $nama_batch = '-';
        $data_batch = $this->batch_model->selectone($id_batch);
        foreach ($data_batch->result() as $row) {
            $nama_batch = $row->NAMA_BATCH;
        }

        $pdf_filename = 'Name tag ' . $nama_batch . '' . '.pdf';
        $link_download = ($download_pdf == TRUE) ? '' : anchor(base_url() . 'peserta_fix/printPDF/true/' . $id_batch, 'Download Pdf');

        //start count jumlah peserta
        $sql = $this->db->query("SELECT COUNT(ID_PESERTA) AS CEK_JUMLAH FROM PESERTA WHERE ID_BATCH = " . $id_batch . " AND STATUS_PESERTA>0 AND STATUS>0");
        $jumlah_peserta = '';
        foreach ($sql->result() as $rows) {
            $jumlah_peserta = $rows->CEK_JUMLAH;
        }

        $data['peserta'] = $this->peserta_fix_model->get_data_peserta_fix($id_batch);
        $data['nama_batch'] = $nama_batch;
        $data['jumlah_peserta'] = $jumlah_peserta;
        $data['cp'] = $this->session->userdata('cp_lisensi');
        $data['header_foto'] = "images/print/header_kamar.jpg";
        $data['footer_foto'] = "images/print/footer_kamar.jpg";
        $this->load->view("peserta/cetak_name_tag", $data);

        $data_kamar = array(
            'data_info' => $data,
            'link_download' => $link_download
        );

        $user_info = $this->load->view('peserta/cetak_name_tag', $data_kamar, true);

        if ($download_pdf == TRUE)
            generate_pdf($user_info, $pdf_filename, "portrai");
        else {
            echo $user_info;
        }
    }

    public function plot_kamar2($id_batch) {

        //start cek data batch
        $sql = $this->db->query("SELECT COUNT(ID_BATCH) AS CEK_BATCH FROM KAMAR2 WHERE ID_BATCH = " . $id_batch . " AND IDKOTA_PESERTA_1 != IDKOTA_PESERTA_2 AND IDKOTA_PESERTA_2 != 0");
        $cek_batch = '';
        foreach ($sql->result() as $rows) {
            $cek_batch = $rows->CEK_BATCH;
        }


        $counter = 1;
        $record_peserta = $this->db->query("SELECT * FROM KAMAR2 WHERE ID_BATCH = " . $id_batch . " AND IDKOTA_PESERTA_1 != IDKOTA_PESERTA_2 AND IDKOTA_PESERTA_2 != 0");
        foreach ($record_peserta->result() as $peserta) {
            $array[$counter] = $peserta->PESERTA_1;
            $counter++;
            $array[$counter] = $peserta->IDKOTA_PESERTA_1;
            $counter++;
            $array[$counter] = $peserta->PESERTA_2;
            $counter++;
            $array[$counter] = $peserta->IDKOTA_PESERTA_2;
            $counter++;
        }
        echo $array[1];
        $counter = $counter - 1;
        echo $counter;
        echo '=----';
        echo $cek_batch;

        //$counter_kamar = 2;
        $counter_idkota1 = 2;
        $counter_idkota2 = 4;
        while ($counter_idkota2 <= $counter) {
            if ($array[$counter_idkota1] != $array[$counter_idkota2]) {
                echo '</br>';
                echo 'tukar';
            }

            $counter_idkota1 = $counter_idkota1 + 4;
            $counter_idkota2 = $counter_idkota2 + 4;
        }





//        if ($cek_batch > 0) {
//            redirect('peserta/peserta_fix/edit_plot_kamar/'.$id_batch.'');
//        }
//        //end cek
//        
//        else {
//            $this->session->set_userdata('id_batch', $id_batch);
//
//            $data['title'] = 'Plot Kamar Peserta';
//            $data['plot_kamar_peserta_cow'] = $this->peserta_fix_model->plot_kamar_cow($id_batch);
//            $data['plot_kamar_peserta_cew'] = $this->peserta_fix_model->plot_kamar_cew($id_batch);
//
//            $this->template->write_view('header', 'template/header', $data);
//            $this->template->write_view('content', 'peserta/plot_peserta', $data);
//            $this->template->write_view('footer', 'template/footer', $data);
//            $this->template->render();
//        }
    }

}

/* End of file pegawai.php */
/* Location: ./application/controllers/pegawai.php */